<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use App\Services\Ip2RegionService;

class Ip2RegionServiceProvider extends ServiceProvider
{
    public function register()
    {
        $this->app->singleton('ip2region', function ($app) {
            $cachePolicy = config('ip2region.cache_policy', 'vectorIndex');
            return new Ip2RegionService($cachePolicy);
        });

        $this->app->bind(Ip2RegionService::class, function ($app) {
            $cachePolicy = config('ip2region.cache_policy', 'vectorIndex');
            return new Ip2RegionService($cachePolicy);
        });
    }

    public function boot()
    {
        // 发布配置文件
        $this->publishes([
            __DIR__.'/../../config/ip2region.php' => config_path('ip2region.php'),
        ], 'ip2region-config');
    }
}
